package com.teemor.blog.controller;

import com.teemor.blog.api.ITagApiService;
import com.teemor.blog.bean.condition.TbTagCondition;
import com.teemor.blog.bean.dto.input.tag.AddTagIPo;
import com.teemor.blog.bean.dto.input.tag.QryTagsIPo;
import com.teemor.blog.bean.dto.input.tag.UpdTagIPo;
import com.teemor.blog.bean.dto.output.tag.QryTagOPo;
import com.teemor.blog.bean.dto.output.tag.QryTagsOPo;
import com.teemor.blog.bean.entity.TbTag;
import com.teemor.blog.service.ITagService;
import com.teemor.common.bean.utils.BeanConvertor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: zhoulk
 * @Description: 原子服务API接口实现
 * @date: 2020/03/24 17:33:32
 */
@RestController
public class TagController implements ITagApiService {
    @Autowired
    private ITagService iTagService;

    @Override
    public QryTagOPo qryTag(@PathVariable Integer id) {
        return BeanConvertor.convertBean(iTagService.qryTagById(id), QryTagOPo.class);
    }

    @Override
    public int countTag(@RequestBody QryTagsIPo inParam) {
        TbTagCondition condition = BeanConvertor.convertBean(inParam, TbTagCondition.class);
        return iTagService.countTag(condition);
    }

    @Override
    public List<QryTagsOPo> qryTags(@RequestBody QryTagsIPo inParam) {
        TbTagCondition condition = BeanConvertor.convertBean(inParam, TbTagCondition.class);
        return BeanConvertor.convertBeanList(iTagService.qryTags(condition), QryTagsOPo.class);
    }

    @Override
    public void updTag(@RequestBody UpdTagIPo inParam) {
        TbTag tbTag = BeanConvertor.convertBean(inParam, TbTag.class);
        iTagService.updTagById(tbTag);
    }

    @Override
    public void addTag(@RequestBody AddTagIPo inParam) {
        TbTag tbTag = BeanConvertor.convertBean(inParam, TbTag.class);
        iTagService.addTag(tbTag);
    }
}